VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "DAOUsuario"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'---------------------------------------------------------------------------------------
' Module    : DAOUsuario
' DateTime  : 30/11/2011 12:14
' Author    :
' Purpose   : Clase DAO Usuario
'---------------------------------------------------------------------------------------
Option Explicit
Private mvarConnection As utilConexion
Public Property Set Connection(ByVal vData As utilConexion)
    Set mvarConnection = vData
End Property
Public Function eliminar(bean As busuario) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "DELETE FROM usuario WHERE sCodigo= '" + CStr(bean.sNombre) + "'"
mvarConnection.Connection.Execute sql
eliminar = UtilConstantes.OPT_DATOS_ELIMINADOS
hnderr:
If Err.Number = 0 Then Exit Function
eliminar = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function guardarNuevo(bean As busuario) As Boolean
On Error GoTo hnderr
Dim sql As String
sql = "INSERT INTO usuario(sCodigo,sNombre, sClave, dFecExpiracion, nEstado, nPerfil) "
sql = sql + " VALUES ('" + bean.sNombre + "','" + bean.sNombre + "','"
sql = sql + bean.sClave + "',"
sql = sql + CStr(bean.bEstado.ncodigo) + "," + CStr(bean.bperfil.ncodigo) + ")"
mvarConnection.Connection.Execute sql
hnderr:
If Err.Number = 0 Then Exit Function
guardarNuevo = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function actualizar(bean As busuario) As Integer
On Error GoTo hnderr
Dim sql As String
sql = "UPDATE usuario SET sNombre ='" + bean.sNombre + "', sClave='" + bean.sClave + "', "
sql = sql + " nEstado =" + CStr(bean.bEstado.ncodigo) + ", "
sql = sql + " nPerfil =" + CStr(bean.bperfil.ncodigo) + " WHERE sCodigo = '" + bean.sNombre + "'"
mvarConnection.Connection.Execute sql
hnderr:
If Err.Number = 0 Then Exit Function
actualizar = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function cambiarClave(bean As busuario) As Integer
On Error GoTo hnderr:
Dim sql As String
sql = "select * from proc_cambiarclave('" + bean.sNombre + "','" + bean.sClave + "')"
mvarConnection.Connection.Execute sql
cambiarClave = UtilConstantes.OPT_DATOS_GUARDADOS
hnderr:
If Err.Number = 0 Then Exit Function
cambiarClave = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function login(ByRef bean As busuario) As busuario
On Error GoTo hnderr
Dim sql As String
Dim rst As New Recordset
Dim record As busuario
sql = "SELECT sNombre, sNombre,  "
sql = sql + " estado.nCodigo as nCodEstado, estado.sDescripcion as sEstado,"
sql = sql + " perfil.nCodigo as nCodPerfil , perfil.sDescripcion as sPerfil "
sql = sql + " FROM estado INNER JOIN (perfil INNER JOIN usuario "
sql = sql + " ON perfil.nCodigo = usuario.nPerfil) ON estado.nCodigo = usuario.nEstado "
sql = sql + " WHERE sNombre = '" + bean.sNombre + "' and sClave ='" + bean.sClave + "'"
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
If Not rst.EOF Then
    Set record = New busuario
    If Not IsNull(rst.Fields("sNombre")) Then record.sNombre = rst.Fields("sNombre").value
    If Not IsNull(rst.Fields("nCodEstado")) Then record.bEstado.ncodigo = rst.Fields("nCodEstado").value
    If Not IsNull(rst.Fields("sEstado")) Then record.bEstado.sDescripcion = rst.Fields("sEstado").value
    If Not IsNull(rst.Fields("nCodperfil")) Then record.bperfil.ncodigo = rst.Fields("nCodPerfil").value
    If Not IsNull(rst.Fields("sPerfil")) Then record.bperfil.sDescripcion = rst.Fields("sPerfil").value
End If
Set login = record
hnderr:
If Err.Number = 0 Then Exit Function
login = UtilConstantes.OPT_ERROR_ENCONTRADO
cloneError Err
Err.Clear
End Function
Public Function getLista(bean As busuario) As Collection
Dim sql As String
Dim rst As New Recordset
Dim list As New Collection
Dim record As New busuario
sql = "SELECT sCodigo, sNombre, sClave,  estado.nCodigo as nCodEstado, estado.sDescripcion as sEstado,"
sql = sql + " dFecExpiracion , perfil.nCodigo as nCodPerfil , perfil.sDescripcion as sPerfil "
sql = sql + " FROM estado INNER JOIN (perfil INNER JOIN usuario "
sql = sql + " ON perfil.nCodigo = usuario.nPerfil) ON estado.nCodigo = usuario.nEstado "
sql = sql + " Where "
sql = sql + " sNombre LIKE '%" + CStr(bean.sNombre) + "%' "
If Val(bean.bEstado.ncodigo) > 0 Then sql = sql + " AND estado.nCodigo =  " + CStr(bean.bEstado.ncodigo) + " "
If Val(bean.bperfil.ncodigo) > 0 Then sql = sql + " AND perfil.nCodigo = " + CStr(bean.bperfil.ncodigo) + " "
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
While Not rst.EOF
    Set record = New busuario
    If Not IsNull(rst.Fields("sNombre")) Then record.sNombre = rst.Fields("sNombre").value
    If Not IsNull(rst.Fields("sClave")) Then record.sClave = rst.Fields("sClave").value
    If Not IsNull(rst.Fields("nCodEstado")) Then record.bEstado.ncodigo = rst.Fields("nCodEstado").value
    If Not IsNull(rst.Fields("sEstado")) Then record.bEstado.sDescripcion = rst.Fields("sEstado").value
    If Not IsNull(rst.Fields("nCodperfil")) Then record.bperfil.ncodigo = rst.Fields("nCodPerfil").value
    If Not IsNull(rst.Fields("sPerfil")) Then record.bperfil.sDescripcion = rst.Fields("sPerfil").value
    rst.MoveNext
    list.Add record
Wend
Set getLista = list
End Function
Public Function getUsuario(bean As busuario) As busuario
Dim sql As String
Dim rst As New Recordset
Dim record As New busuario
sql = "SELECT sCodigo, sNombre, sClave,  estado.nCodigo as nCodEstado, estado.sDescripcion as sEstado,"
sql = sql + " dFecExpiracion , perfil.nCodigo as nCodPerfil , perfil.sDescripcion as sPerfil "
sql = sql + " FROM estado INNER JOIN (perfil INNER JOIN usuario "
sql = sql + " ON perfil.nCodigo = usuario.nPerfil) ON estado.nCodigo = usuario.nEstado "
sql = sql + " Where "
sql = sql + " sCodigo ='" + CStr(bean.sNombre) + "' "
rst.Open sql, mvarConnection.Connection, adOpenForwardOnly
If Not rst.EOF Then
    Set record = New busuario
    If Not IsNull(rst.Fields("sCodigo")) Then record.sNombre = rst.Fields("sCodigo").value
    If Not IsNull(rst.Fields("sClave")) Then record.sClave = rst.Fields("sClave").value
    If Not IsNull(rst.Fields("nCodEstado")) Then record.bEstado.ncodigo = rst.Fields("nCodEstado").value
    If Not IsNull(rst.Fields("sEstado")) Then record.bEstado.sDescripcion = rst.Fields("sEstado").value
    If Not IsNull(rst.Fields("nCodperfil")) Then record.bperfil.ncodigo = rst.Fields("nCodPerfil").value
    If Not IsNull(rst.Fields("sPerfil")) Then record.bperfil.sDescripcion = rst.Fields("sPerfil").value
End If
Set getUsuario = record
End Function



